'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ChatSelectuserCtrl
 * @description
 * # ChatSelectuserCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ChatSelectuserCtrl', function (ChatStatus, DataService, RongYService, openApi, $rootScope) {
        var vm = this;
        this.peoplelist = [];
        $rootScope.userArr = $rootScope.userArr || []
        this.handleUser = function (userObj) {
            if (userObj.selected) {
                $rootScope.userArr.push(userObj)
            } else {
                $rootScope.userArr = $rootScope.userArr.filter(function (item, index) {
                    return item.id != userObj.id
                })
            }
            $rootScope.$broadcast("userArrchange")
        }
        var init = function () {
            var param = getAllparam();
            console.log(param);
            DataService.getData(openApi.selectuser, param).then(function (data) {
                vm.peoplelist = data
            })
        }
        var getAllparam = function () {
            var param = {};
            var status = ChatStatus.getStatus();
            var type = ChatStatus.getChatType();
            var targetId = ChatStatus.getTargetId();
            /*
            flag=1,2,3分别对应所有人，群组,讨论组
             */
            param.flag = 1
            if (type == ChatStatus.GROUP) {
                if (status == ChatStatus.UPDATE) {
                    param.flag = 2
                    param.id = targetId
                }
            }
            return param;
        }
        this.confirm = function () {
            RongYService.startChat()
        }
        init();
    });
